package com.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.beans.DiskFileInfo;
import com.beans.UserInfo;
import com.dao.HdfsDao;
import com.dao.impl.HdfsDaoImpl;

@WebServlet("/HiveServlet")
public class HiveServlet extends HttpServlet {
	private HdfsDao hdfsDao=new HdfsDaoImpl();

	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String flag=request.getParameter("flag");
		
		if("searchLogFiles".equals(flag)) {
			searchLogFiles(request,response);
		}
	}

	private void searchLogFiles(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		UserInfo user=(UserInfo) request.getSession().getAttribute("session_user");
		
		//约定好,日志文件必须放在每个用户的 log目录下
		String parent=user.getUserName()+"/log"; 
		
		DiskFileInfo[] hdfsFileList = hdfsDao.getSubFileList(parent);
		request.setAttribute("hdfsFileList", hdfsFileList);
		
		request.getRequestDispatcher("/hive/list-log.jsp").forward(request, response);
	}
	
}
